package forecasting.converter;


public class RealValue extends FeatureType {
	public final static String REAL_VALUE = " NUMERIC";
	
	public final static double MIN_VALUE = 0;
	
	public final static double MAX_VALUE = 1.0;
	
	private LinearTransform mTransform;
	
	public RealValue(String name, double val) {
		super(name);
		mTransform = new LinearTransform(MIN_VALUE, MAX_VALUE);
		mTransform.register(val);
	}
	
	public static boolean isReal(String val) {
		boolean isReal = true;
		try {
			// convert to java-recognized scientific notation;		
			convertToDouble(val);
		} catch (NumberFormatException e) {
			isReal = false;
		}
		return isReal;
	}

	/**
	 * Converts a string to java's scienfic format. If this is not a double number, then this returns garbage. The calling
	 * context is 
	 * 
	 * 
	 * 
	 * @param val
	 * @return
	 */
	public static double convertToDouble(final String val) {
		final String str = val.replace('d', 'e');
		final String str2 = str.replace('D', 'E');
		return Double.parseDouble(str2);
	}
	
	public void registerValue(final double value) {
		mTransform.register(value);				
	}
	
	public double transform(final double value) {
		return mTransform.transform(value);
	}
	
	@Override
	public String toString() {
		return super.toString() + name + REAL_VALUE;
	}
	
}
